<template>
	<view class="">
		<view class="nav-back">
			<top-heigth backTitle="资质照片"></top-heigth>
		</view>	
					
		<view class="content-box" v-if="detail">
			<view class="photo-h1">身份证照片（人像面）</view>
			<uv-upload
				:fileList="fileListFace"
				name="Face"
				multiple
				:maxCount="1"
				width="230rpx"
				height="200rpx"
				@afterRead="afterRead" 
				@delete="deletePic"
			>
			</uv-upload>
			
			<view class="photo-h1">身份证照片（国徽面）</view>
			<uv-upload
				:fileList="fileListBack"
				name="Back"
				multiple
				:maxCount="1"
				width="230rpx"
				height="200rpx"
				@afterRead="afterRead" 
				@delete="deletePic"
			>
			</uv-upload>
			
			<view class="photo-h1">从业资格证照片</view>
			<uv-upload
				:fileList="fileListSign"
				name="Sign"
				multiple
				:maxCount="1"
				width="230rpx"
				height="200rpx"
				@afterRead="afterRead" 
				@delete="deletePic"
			>
			</uv-upload>
						
			<view class="photo-h1">健康证照片</view>
			<uv-upload
				:fileList="fileListHealth"
				name="Health"
				multiple
				:maxCount="1"
				width="230rpx"
				height="200rpx"
				@afterRead="afterRead"
				@delete="deletePic"
			>
			</uv-upload>
			
			<view class="photo-h1">其他资质</view>
			<uv-upload
				:fileList="fileListSignBack"
				name="SignBack"
				multiple
				:maxCount="1"
				width="230rpx"
				height="200rpx"
				@afterRead="afterRead" 
				@delete="deletePic"
			>
			</uv-upload>
			
			<view class="photo-font">
				<view>1.为保证您的隐私安全，身份证照片仅作为平台审核使用、无其他展示，请放心上传；</view>
				<view>2.从业资格和健康证照片将在东方到家app中进行展示,请根据您的服务行业进行上传；</view>
				<view>3.因资质照片需作为审核依据，在拍摄照片时，请勿开设美颜/滤镜等，以确保照片内容清晰真实。</view>
			</view>
			
			<view class="login-but" @click="saveInfo" v-if="this.detail && this.detail.checkStatus != 1">提交</view>
			<view style="height: 100rpx;"></view>
		</view>
			
	</view>
</template>

<script>
	import TopHeigth from '@/components/TopHeigth.vue'
	import config from '@/common/config'
	export default {
		data() {
			return {
				userInfo: uni.getStorageSync('userInfo'),
				detail: null,
				fileListFace: [],
				fileListBack: [],
				fileListSign: [],
				fileListSignBack: [],
				fileListHealth: [],
			}
		},
		components: { TopHeigth },
		onLoad() {
			this.getDetail()// 技师详情
		},
		mounted() {
			
		},
		methods: {
			getDetail(){ // 技师详情
				uni.$u.http.post('/api/shop/v1_0/tAppStaffRCA/turnTAppStaffInfo',{
					id: this.userInfo.id,
				}).then((res) => {
					this.detail = res.data
					this.fileListFace= 		res.data.cardImgFace ? [{url: res.data.cardImgFace}] : []
					this.fileListBack= 		res.data.cardImgBack ? [{url: res.data.cardImgBack}] : []
					this.fileListSign= 		res.data.certificationImgFace ? [{url: res.data.certificationImgFace}] : []
					this.fileListSignBack= 	res.data.certificationImgBack ? [{url: res.data.certificationImgBack}] : []
					this.fileListHealth= 	res.data.bodyImg ? [{url: res.data.bodyImg}] : []
				})
			},
			saveInfo(){
				uni.$u.http.post('/api/shop/v1_0/tAppStaffRCA/updateTAppStaff', {
					id: this.detail.id,
					version: this.detail.version,
					cardImgFace: this.fileListFace.length > 0 ? this.fileListFace[0].url : null,
					cardImgBack: this.fileListBack.length > 0 ? this.fileListBack[0].url : null,
					certificationImgFace: this.fileListSign.length > 0 ? this.fileListSign[0].url : null,
					certificationImgBack: this.fileListSignBack.length > 0 ? this.fileListSignBack[0].url : null,
					bodyImg: this.fileListHealth.length > 0 ? this.fileListHealth[0].url : null,
					checkStatus: 0
				}).then((res) => {
					if(res.code == 200){
						uni.showToast({
							icon: "none",
							title: res.message
						})
						setTimeout(() => {
							uni.navigateBack()
						}, 1000)
					}
				})
			},
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, {
						url: result
					})
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: uni.$u.http.getSignUrl("/api/system/loginController/uploadImage"), // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						success: (res) => {
							resolve(JSON.parse(res.data).data)
						}
					});
				})
			},
			deletePic(event){
				this[`fileList${event.name}`].splice(event.index, 1)
			}
		}
	}
</script>

<style lang="scss" scoped>
	@mixin flex($direction: row) {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: $direction;
	}
	.uv-nav-slot {
		@include flex;
		align-items: center;
		justify-content: space-between;
		border-width: 0.5px;
		border-radius: 100px;
		border-color: #dadbde;
		padding: 3px 7px;
		opacity: 0.8;
	}
	
	.photo-h1{
		font-size: 30rpx;
		font-weight:bold;
		color: #333;
		padding: 32rpx 0 24rpx;
	}
	/deep/ .uv-avatar__image--circle{
		border-radius:0;
	}
	.up-box{
		@include flex;
		align-items: center;
		justify-content: center;
		width: 160rpx;
		height: 160rpx;
		background: #F8F8F8;
		border: 2rpx solid #D8D8D8;
		border-radius: 8rpx;
	}
	.photo-font{
		font-size: 24rpx;
		color: #999;
		line-height: 34rpx;
		margin-top: 40rpx;
		margin-bottom: 50rpx;
	}
</style>
